<?php
	class Controller {
		
		public $vars;
		public $views;
		public $view;
		
		function __construct($vars) 
		{ 
			$this->vars = $vars;
			$this->views = $this->getViews($vars['module']);
						
			if($this->vars['view'] == null)
				$this->vars['view'] = 'index';
			
			$this->view = new View($this->vars['view'], $this->vars['module']);
			$this->view->title = ucfirst($this->vars['module']);
			$this->view->render();
		}
		
		// Gets all views for the current module
		function getViews($module)
		{
			$views = scandir('library/modules/' . $module . '/views');
			$pos = 0;
			foreach($views as $view) {
				$ex = explode('.', $view);
				$ex = $ex[count($ex) - 1];
				if($ex != 'php')
					unset($views[$pos]);
				$pos++;
			}
			
			return $views;
		}
}